﻿
namespace SharePointContentGenerator.ContentGeneratorLogic.Core
{
    public class ContentGeneratorNotification
    {
        internal event ContentGenerationTaskEventHandler ContentGenerationTasksStarted;

        internal void DoContentGenerationTasksStarted(int numTasks)
        {
            if (ContentGenerationTasksStarted != null)
            {
                ContentGenerationTasksStarted(this, new ContentGenerationTaskEventArgs()
                {
                    TotalTasks = numTasks
                });
            }
        }

        internal event ContentGenerationTaskEventHandler ContentGenerationTasksFinished;

        internal void DoContentGenerationTasksFinished()
        {
            if (ContentGenerationTasksFinished != null)
            {
                ContentGenerationTasksFinished(this, new ContentGenerationTaskEventArgs());
            }
        }

        internal event ContentGenerationTaskEventHandler ContentGenerationTaskChanging;

        internal bool DoContentGenerationTaskChanging(string taskName, int currentTaskIndex, int numTasks)
        {
            bool result = false;
            if (ContentGenerationTaskChanging != null)
            {
                ContentGenerationTaskEventArgs e = new ContentGenerationTaskEventArgs() 
                {
                    TotalTasks = numTasks,
                    CurrentTaskIndex = currentTaskIndex,
                    TaskName = taskName
                };

                ContentGenerationTaskChanging(this, e);

                result = e.Cancel;
            }

            return result;
        }

        internal event ContentGenerationItemEventHandler ContentGenerationItemsStarted;

        internal void DoContentGenerationItemsStarted(int numItemsToCreate)
        {
            if (ContentGenerationItemsStarted != null)
            {
                ContentGenerationItemsStarted(this, new ContentGeneratorItemEventArgs()
                {
                    TotalItems = numItemsToCreate
                });
            }
        }

        internal event ContentGenerationItemEventHandler ContentGenerationItemsFinished;

        internal void DoContentGenerationItemsFinished()
        {
            if (ContentGenerationItemsFinished != null)
            {
                ContentGenerationItemsFinished(this, new ContentGeneratorItemEventArgs());
            }
        }

        internal event ContentGenerationItemEventHandler ContentGenerationItemChanging;

        internal bool DoContentGenerationItemChanging(string listName, int currentIndex, int totalItems, ContentGeneratorAction currentAction)
        {
            bool result = false;
            if (ContentGenerationItemChanging != null)
            {
                ContentGeneratorItemEventArgs e = new ContentGeneratorItemEventArgs()
                {
                    ItemName = listName,
                    CurrentItemIndex = currentIndex,
                    TotalItems = totalItems,
                    CurrentAction = currentAction,
                };

                ContentGenerationItemChanging(this, e);

                result = e.Cancel;
            }

            return result;
        }
    }
}
